<template>
	<!-- 点亮记录 -->
	<view class="page">
		<view class="popover">
			<view class="top">
				<view class="region">已点亮{{selectCityItem}}</view>
				<!-- 切换城市标签 -->
				<view class="lab" @click="show=true">
					<text class="city">{{selectCityItem}}</text>
					<u-icon name="arrow-down-fill" color="#666666" size="16rpx"></u-icon>
				</view>
			</view>
			<view class="center">
				<text class="number">{{pageDetail.city}} </text> 个{{selectCityItem=='中国'?'城市':'地区'}}
			</view>
			<view class="bottom">
				<image class="bulb" src="/pages/my/static/bulb.png" mode=""></image>
				已点亮{{selectCityItem}} <text class="num">{{pageDetail.city}}</text>
				个{{selectCityItem=='中国'?'城市':'地区'}}，总计参加了 <text class="num">{{pageDetail.researchNum}}</text> 个研学活动
			</view>
		</view>

		<view class="lit_record">点亮记录</view>

		<view class="main" v-for="(item,index) in recordList" :key="index">
			<view class="date">{{item.date}}</view>
			<view class="item" v-for="(v1,i1) in item.recordList" :key="i1">
				<view class="first">
					<text class="city">{{v1.city}}</text> {{v1.createTime}} 点亮
				</view>
				<view class="activity">
					<image class="hat" src="/pages/my/static/hat.png" mode=""></image>
					{{v1.researchName}}
				</view>
			</view>

		</view>

		<u-popup :show="show" :round="10" mode="bottom" closeable @close="show=false">
			<view class="pop">
				<view class="title">已点亮{{selectCityItem=='中国'?'城市':'地区'}}</view>
				<view class="country">{{selectCityItem}}
					<view class="city" :class="{city_a:selectCityItem=='中国'}" @click="selectCity('中国')">全国</view>
				</view>
				<view class="citys">
					<view class="city" :class="{city_a:selectCityItem==item}" v-for="(item,index) in cityList"
						:key="index" @click="selectCity(item)">{{item}}</view>
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	export default {
		name: "lightUpRecord",
		data() {
			return {
				show: false,
				selectCityItem: '',
				cityList: [],
				pageDetail: {},
				recordList: []
			};
		},
		onLoad(opt) {
			console.log(opt, 'this.selectCityItem');
			this.selectCityItem = opt.city
			this.getLightListFn()
			this.selectCity(this.selectCityItem)
		},
		onShow() {},
		methods: {

			// 点亮城市
			getLightListFn() {
				this.$api.getLightList().then(res => {
					console.log(res, '点亮城市');
					this.cityList = res.data
				})
			},

			// 选择城市
			selectCity(v) {
				this.selectCityItem = v
				this.show = false
				if (v == "中国") {
					this.getCityListFn()
					this.getCityRecordFn()
				} else {
					this.getAreaListFn()
					this.getAreaRecordFn()
				}
			},

			// 我的足迹-城市
			getCityListFn() {
				this.$api.getCityList().then(res => {
					console.log(res, '我的足迹-城市');
					this.pageDetail = res.data
				})
			},

			// 查询城市数据
			getAreaListFn() {
				this.$api.getAreaList({
					city: this.selectCityItem
				}).then(res => {
					console.log(res, '查询城市数据');
					this.pageDetail = res.data
				})
			},
			// 我的足迹-城市-点亮记录
			getCityRecordFn() {
				this.$api.getCityRecord().then(res => {
					console.log(res, '中国111');
					this.recordList = res.data.dateInfo
				})
			},
			// 我的足迹-地区-点亮记录
			getAreaRecordFn() {
				this.$api.getAreaRecord({
					city: this.selectCityItem
				}).then(res => {
					console.log(res, '城市');
					this.recordList = res.data.dateInfo
				})
			}

		}
	};
</script>

<style lang="scss" scoped>
	.popover {
		width: 750rpx;
		padding: 32rpx;
		box-sizing: border-box;

		.top {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.region {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #666666;
				line-height: 33rpx;
			}

			.lab {
				padding: 10rpx 16rpx;
				box-sizing: border-box;
				border-radius: 12rpx;
				border: 1rpx solid #666666;
				display: flex;
				align-items: center;

				.city {
					font-size: 24rpx;
					color: #333333;
					line-height: 28rpx;
					margin: 0rpx 34rpx 0rpx 0rpx;
				}
			}
		}

		.center {
			font-size: 28rpx;
			color: #1A1A1A;
			line-height: 33rpx;
			margin: 40rpx 0 32rpx;

			.number {
				font-weight: 800;
				font-size: 64rpx;
				line-height: 75rpx;
				margin-right: 14rpx;
			}
		}

		.bottom {
			display: flex;
			align-items: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #666666;
			line-height: 28rpx;

			.bulb {
				width: 21rpx;
				height: 24rpx;
				margin-right: 10rpx;
			}

			.num {
				color: #333333;
			}
		}
	}

	.lit_record {
		background: #F7F7F7;
		font-weight: bold;
		font-size: 32rpx;
		color: #000000;
		line-height: 38rpx;
		padding: 18rpx 32rpx;
		box-sizing: border-box;
	}

	.main {
		padding: 32rpx 32rpx 0;
		box-sizing: border-box;
		border-bottom: 8rpx solid #F7F7F7;

		.date {
			font-weight: bold;
			font-size: 32rpx;
			color: #1A1A1A;
			line-height: 38rpx;
		}

		.item {
			padding: 24rpx 0;
			border-bottom: 1rpx solid #E6E6E6;

			&:nth-last-child(1) {
				border: none;
			}

			.first {
				font-size: 24rpx;
				color: #333333;
				text-align: left;
				font-style: normal;
				text-transform: none;

				.city {
					font-size: 28rpx;
				}
			}
		}



		.activity {
			margin-top: 16rpx;
			display: flex;
			align-items: center;
			gap: 12rpx;
			font-weight: 400;
			font-size: 24rpx;
			color: #666666;
			line-height: 28rpx;

			.hat {
				width: 31rpx;
				height: 24rpx;
			}
		}

	}

	.pop {
		padding: 32rpx 32rpx 150rpx;
		box-sizing: border-box;
		font-weight: bold;
		font-size: 32rpx;
		color: #1A1A1A;
		line-height: 38rpx;

		.country {
			font-weight: bold;
			font-size: 28rpx;
			color: #333333;
			line-height: 33rpx;
			margin: 32rpx 0 20rpx;
			display: flex;
			align-items: center;
			gap: 10rpx;
		}

		.citys {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			gap: 28rpx;
		}

		.city {
			background: #F0F2F5;
			border-radius: 6rpx;
			padding: 12rpx 30rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #808080;

			&.city_a {
				background: #1183FF;
				color: #FFFFFF;
			}
		}
	}
</style>